package com.aiex.framework.db.config.listener;

import com.aiex.framework.db.config.base.BaseDO;
import com.aiex.framework.security.bo.LoginUser;
import com.mybatisflex.annotation.InsertListener;
import org.springframework.security.core.context.SecurityContextHolder;

public class FlexInsertListener implements InsertListener {


    @Override
    public void onInsert(Object entity) {
        BaseDO baseDO = (BaseDO) entity;
        LoginUser loginUser = (LoginUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        baseDO.setCreateBy(loginUser.getId());
        baseDO.setModifyBy(loginUser.getId());
    }
}
